const XTPath = {
	getCurrentPages(context) {
		let curPage;
		if (context != undefined) curPage = context.getCurrentPages();
		else curPage = getCurrentPages();
		if (curPage === undefined) {
			console.log("curPage 为空!!!");
		}
		return curPage;
	},
	// 不好改变this指向。赋给一个变量
	currentPath(curPage) {
		if (curPage == undefined) return "";
		let route = curPage[curPage.length - 1].route; //获取当前页面的路由
		let params = curPage[curPage.length - 1].options; //获取当前页面参数，如果有则返回参数的对象，没有参数返回空对象{}
		if (params == undefined) return route;
		let query = '';
		let keys = Object.keys(params); //获取对象的key 返回对象key的数组
		if (keys.length > 0) {
			query = keys.reduce((pre, cur) => {
				return pre + cur + '=' + params[cur] + '&';
			}, '?').slice(0, -1);
		}
		return route + query
	},
	// 获取当前页面路径
	getPath(context) {
		return this.currentPath(this.getCurrentPages(context));
	}
}


export {
	XTPath
}